package hotel.switchs.oversea.online.controller;

import hotel.base.oversea.utils.DateUtil;
import hotel.base.oversea.utils.Result;
import hotel.base.oversea.vo.meituan.request.room.CompareRoomForFpVO;
import hotel.switchs.oversea.api.VO.CompareHotelRoomVo;
import hotel.switchs.oversea.api.VO.request.GetRoomListVo;
import hotel.switchs.oversea.api.VO.request.SetHotelUpVo;
import hotel.switchs.oversea.api.entity.SwitchFixPointSetEntity;
import hotel.switchs.oversea.api.entity.SwitchHotelActiveGenreEntity;
import hotel.switchs.oversea.api.entity.SwitchPushHotelLogEntity;
import hotel.switchs.oversea.online.service.SwitchHotelUpService;
import hotel.switchs.oversea.online.service.SwitchOrderInfoService;
import hotel.switchs.oversea.online.service.SwitchPriceBaseSetService;
import hotel.switchs.oversea.online.service.SwitchPushHotelLogService;
import hotel.switchs.oversea.online.service.impl.SwitchRestTempaleUtilsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.OutputStream;
import java.net.URLEncoder;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @Author lmf
 * @Date 2020/6/2 15:04
 * 房价 相关控制器
 **/
@RestController
@Slf4j
@Api(value = "switchHotelUpController", tags = {"房价相关控制器"})
@RequestMapping("/switchHotelUp")
public class SwitchHotelUpController {

    @Autowired
    private SwitchHotelUpService switchHotelUpService;


    @Autowired
    private SwitchPushHotelLogService switchPushHotelLogService;

    @Autowired
    private SwitchPriceBaseSetService switchPriceBaseSetService;

    @Autowired
    SwitchRestTempaleUtilsService switchRestTempaleUtilsService;

    @Autowired
    SwitchOrderInfoService switchOrderInfoService;


    @ApiOperation(value = "获取上架酒店和产品信息", notes = "必须经过auth授权")
    @PostMapping("/getUpHotelGoodsData")
    public Result<Object> getUpHotelGoodsData() {
        return switchHotelUpService.getUpHotelGoodsData();
    }

    @ApiOperation(value = "获取上架酒店和产品信息", notes = "必须经过auth授权")
    @PostMapping("/getUpHotelGoodsDataForBasicRoom")
    public Result<Object> getUpHotelGoodsDataForBasicRoom() {
        return switchHotelUpService.getUpHotelGoodsDataForBasicRoom();
    }
    @ApiOperation(value = "获取上架酒店和产品信息指定酒店", notes = "必须经过auth授权")
    @PostMapping("/getUpHotelGoodsDataByHotelId")
    public Result<Object> getUpHotelGoodsDataByHotelId(@RequestBody Map map) {
        Integer mtHotelId = (Integer) map.get("mtHotelId");
        return switchHotelUpService.getUpHotelGoodsDataByHotelId(mtHotelId);
    }
    /***
     * @Author: lmf
     * @Date: 2021/2/2
     * 美团主动查询价格，获取售卖的酒店列表数据
     */
    @ApiOperation(value = "获取商家酒店信息升序返回", notes = "必须经过auth授权")
    @PostMapping("/getUpHotelAsc")
    public Result<Object> getUpHotelAsc() {
        return switchHotelUpService.getUpHotelAsc();
    }

    /***
     * @Author: lmf
     * @Date: 2021/2/2
     * 美团主动查询价格，获取售卖的酒店列表数据，初始化
     */
    @ApiOperation(value = "获取商家酒店信息升序返回", notes = "必须经过auth授权")
    @PostMapping("/initHotelData")
    public Result<Object> initHotelData() {
        return switchHotelUpService.initHotelData();
    }

    /***
     * @Author: lmf
     * @Date: 2020/12/23
     * 优势酒店+普通酒店数据返回
     */
    @ApiOperation(value = "获取售卖酒店信息供美团接口升序返回", notes = "必须经过auth授权")
    @PostMapping("/getUpHotelRpOrFtAsc")
    public Result<Object> getUpHotelRpOrFtAsc(@RequestBody Map map) {
        Integer genre = (Integer) map.get("genre");
        return switchHotelUpService.getUpHotelRpOrFtAsc(genre);
    }

    @ApiOperation(value = "获取商家酒店信息降序返回", notes = "必须经过auth授权")
    @PostMapping("/getUpHotelDesc")
    public Result<Object> getUpHotelDesc() {
        return switchHotelUpService.getUpHotelDesc();
    }

    /**
     *
     * @author: lmf
     * @time: 2020/10/27 16:36
     * 导入酒店数据,开启酒店售卖
     */
    @PostMapping("/submitUploadSale")
    @ApiOperation(value = "导入酒店数据,开启酒店售卖", notes = "必须经过auth授权")
    public Result<Object> submitUploadSale(@RequestParam("excelFile") MultipartFile excelFile) {
        if(excelFile.isEmpty()){
            return new Result<>("上传失败");
        }
        return  switchHotelUpService.submitUploadSale(excelFile,1);
    }

    /***
     * @Author: lmf
     * @Date: 2021/1/26
     * 导入数据检查是否有黑名单
     */
    @PostMapping("/sumbitUploadBlack")
    @ApiOperation(value = "导入酒店数据,开启酒店售卖", notes = "必须经过auth授权")
    public Result<Object> sumbitUploadBlack(@RequestParam("excelFile") MultipartFile excelFile) {
        if(excelFile.isEmpty()){
            return new Result<>("上传失败");
        }
        return  switchHotelUpService.sumbitUploadBlack(excelFile);
    }

    /***
     * @Author: lmf
     * @Date: 2020/9/21
     * 导入在售的酒店数据
     */
    @PostMapping("/upExecel")
    @ApiOperation(value = "导入在售的酒店数据",notes = "必须经过oauth授权")
    public Result<Object> upExecel(@RequestParam("excelFile") MultipartFile excelFile) throws IOException {
        if(excelFile.isEmpty()){
            return new Result<>("上传失败");
        }
        return switchHotelUpService.upExecel(excelFile);
    }
    /***
     * @Author: lmf
     * @Date: 2020/9/23
     * 开启全量售卖
     */
    @PostMapping("/upHotelAll")
    @ApiOperation(value = "控制批量上架和批量下架功能",notes = "必须经过oauth授权")
    public Result<Object> aspupHotelAll(@RequestBody SetHotelUpVo setHotelUpVo){
        return switchHotelUpService.upHotelAllNew(setHotelUpVo);
    }
    /**
     * 批量下架功能
     */
    @PostMapping("/downHotelAll")
    @ApiOperation(value = "控制批量下架功能",notes = "必须经过oauth授权")
    public Result<Object> aspdownHotelAll(@RequestBody SetHotelUpVo setHotelUpVo){
        return switchHotelUpService.downHotelAll(setHotelUpVo);
    }
    /**
     * @Author: lmf
     * @Date: 2020/9/21
     * 获取已经上架的酒店列表
     */
    @PostMapping("/getHotelList")
    @ApiOperation(value = "获取已经上架的酒店列表",notes = "必须经过oauth授权")
    public Result<Object> getHotelList(@RequestBody GetRoomListVo getRoomListVo){
        return  switchHotelUpService.getHotelList(getRoomListVo);
    }


    /**
     * @author: lmf
     * @date: 2020/8/14 13:40
     * 后台控制酒店售卖状态
     */
    @PostMapping("/modifyHotelStatus")
    @ApiOperation(value = "后台控制酒店售卖状态",notes = "必须经过oauth授权")
    public Result<Object> aspmodifyHotelStatus(@RequestBody SetHotelUpVo setHotelUpVo){
        return switchHotelUpService.modifyHotelStatus(setHotelUpVo);
    }
    /**
     *
     * @author: lmf
     * @time: 2020/10/15 16:00
     * 上架的酒店
     */
    @GetMapping("/runHotel")
    @ApiOperation(value="上架的酒店循环跑",notes = "必须经过oauth授权")
    public Result<Object> runHotel(){
        return switchHotelUpService.runHotel();
    }

    @ApiOperation(value = "获取上架酒店和产品信息", notes = "必须经过auth授权")
    @PostMapping("/getUpHotelGoodsDataFp")
    public Result<List<CompareRoomForFpVO>> getUpHotelGoodsDataFp() {
        return switchHotelUpService.getUpHotelGoodsDataFp();
    }
    /**
     * 添加相关操作的缓存
     */
    @ApiOperation(value = "添加相关操作的缓存", notes = "必须经过auth授权")
    @GetMapping("/addAllCache")
    public Result<Object> addAllCache(@RequestParam(value = "genre",defaultValue = "0")Integer genre) {
        return switchHotelUpService.addAllCache(genre);
    }
    /***
     * @Author: lmf
     * @Date: 2020/12/8
     * 全量更新出售中的酒店
     */
    @ApiOperation(value = "全量更新出售中的酒店", notes = "必须经过auth授权")
    @GetMapping("/batchUpdateRoomPriceAndStatus")
    public Result<Object> batchUpdateRoomPriceAndStatus(){
        switchHotelUpService.batchUpdateRoomPriceAndStatus();
        return new Result<>();
    }
    /***
     * @Author: lmf
     * @Date: 2020/12/15
     * 定点售卖房型
     */
    @ApiOperation(value = "定点售卖房型",notes = "必须经过auth授权")
    @GetMapping("/bookTime")
    public Result<Object> bookTime(){
        switchHotelUpService.batchUpdateRoomPriceAndStatus();
        return new Result<>();
    }

    /***
     * @Author: lmf
     * @Date: 2020/12/31
     * 0-5点暂时关闭没有订单的酒店
     * 针对夜间只售卖有订单的酒店
     */
    @ApiOperation(value = "针对夜间只售卖有订单的酒店",notes = "必须经过auth授权")
    @GetMapping("/bookTimeCloseNoOrderHotelList")
    public Result<Object> bookTimeCloseNoOrderHotelList(){
        return switchHotelUpService.bookTimeCloseNoOrderHotelList();
    }

    /***
     * @Author: lmf
     * @Date: 2020/12/31
     * 5点-6点开启停售的酒店恢复上线
     */
    @ApiOperation(value = "针对夜间停售酒店重新上架",notes = "必须经过auth授权")
    @GetMapping("/bookTimeStartNoOrderHotelList")
    public Result<Object> bookTimeStartNoOrderHotelList(){
        return switchHotelUpService.bookTimeStartNoOrderHotelList();
    }
    /***
     * @Author: lmf
     * @Date: 2021/1/7
     * 替换一个礼拜没有订单的酒店
     */
    @ApiOperation(value = "替换一个礼拜没有订单的酒店",notes = "必须经过auth授权")
    @GetMapping("/replaceNoOrderHotel")
    public Result<Object> replaceNoOrderHotel(){
        log.info("===========替换一个礼拜没有订单的酒店开始===============");
        return switchHotelUpService.replaceNoOrderHotel();
    }

    /***
     * @Author: lmf
     * @Date: 2021/1/7
     * 从上架表中获取待上架的酒店，进行上架
     */
    @ApiOperation(value = "从上架表中获取待上架的酒店，进行上架",notes = "必须经过auth授权")
    @GetMapping("/againNewHotel")
    public Result<Object> againNewHotel(){
        log.info("=============从上架表中获取待上架的酒店，进行上架=============");
        return switchHotelUpService.againNewHotel();
    }

    /***
     * @Author: lmf
     * @Date: 2021/1/7
     * 增量上酒店
     */
    @ApiOperation(value = "增量新增酒店",notes = "必须经过auth授权")
    @GetMapping("/addHotelList")
    public Result<Object> addHotelList(){
        log.info("=========增量上酒店=============");
        return switchHotelUpService.addHotelList();
    }

    /***
     * @Author: lmf
     * @Date: 2021/1/8
     * 活动上下架
     */
    @ApiOperation(value = "活动上下架",notes = "必须经过auth授权")
    @GetMapping("/activeHotelDownAndUp")
    public Result<Object> activeHotelDownAndUp(){
        log.info("=========活动上下架=============");
        return switchHotelUpService.activeHotelDownAndUp();
    }

    /***
     * @Author: lmf
     * @Date: 2021/1/15
     * 获取在售酒店进行房型数据更新 2021-04-16更新 加分布式锁
     */
    @ApiOperation(value = "获取在售酒店进行房型数据更新",notes = "必须经过auth授权")
    @GetMapping("/saleHotelUpdateRoomInfo")
    public Result<Object> saleHotelUpdateRoomInfo(){
        log.info("=========获取在售酒店进行房型数据更新=============");
        ExecutorService executorService = Executors.newFixedThreadPool(1);
        executorService.submit(() -> {
            switchHotelUpService.saleHotelUpdateRoomInfo();
        });
        executorService.shutdown();
        return new Result<>();
    }

    /***
     * @Author: lmf
     * @Date: 2021/1/27
     * 效验房型的价格房态是否更新，没有重新推送
     */
    @ApiOperation(value = "效验房型的价格房态是否更新，没有重新推送",notes = "必须经过auth授权")
    @RequestMapping("/checkSaleHotelPriceAndStatusIsChange")
    public Result<Object> checkSaleHotelPriceAndStatusIsChange(){
        return switchHotelUpService.checkSaleHotelPriceAndStatusIsChange();
    }

    /***
     * @Author: lmf
     * @Date: 2021/3/23
     * 设置酒店是否更新价格和房态的酒店列表
     */
    @ApiOperation(value = "设置酒店是否更新价格和房态的酒店列表",notes = "必须经过auth授权")
    @RequestMapping("/setCheckSaleHotelPriceAndStatusIsChangeHotelList")
    public Result<Object> setCheckSaleHotelPriceAndStatusIsChangeHotelList(){
        log.info("=========设置酒店是否更新价格和房态的酒店列表=============");
        return switchHotelUpService.setCheckSaleHotelPriceAndStatusIsChangeHotelList();
    }
    /***
     * @Author: lmf
     * @Date: 2021/2/2
     * 获取有订单的酒店的所有产品的取消规则
     */
    @ApiOperation(value ="获取有订单的酒店的所有产品的取消规则",notes = "必须经过auth授权")
    @GetMapping("/getOrderHotelCancelRule")
    public void getOrderHotelCancelRule(HttpServletResponse response){
        log.info("=========获取有订单的酒店的所有产品的取消规则=============");
        XSSFWorkbook wb= switchHotelUpService.getOrderHotelCancelRule();
        String fileName = "有订单的酒店数据.xlsx";
        OutputStream outputStream =null;
        try {
            fileName = URLEncoder.encode(fileName,"UTF-8");
            //设置ContentType请求信息格式
            response.setContentType("application/vnd.ms-excel");
            response.setHeader("Content-disposition", "attachment;filename=" + fileName);
            outputStream = response.getOutputStream();
            wb.write(outputStream);
            outputStream.flush();
            outputStream.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /***
     * @Author: lmf
     * @Date: 2021/2/5
     * 设置定点售卖功能
     */
    @ApiOperation(value ="设置定时售卖",notes = "必须经过auth授权")
    @PostMapping("/setHotelSaleTime")
    public Result<Object> setHotelSaleTime(@RequestBody SwitchFixPointSetEntity switchFixPointSetEntity){
        return  switchHotelUpService.setHotelSaleTime(switchFixPointSetEntity);
    }
    /***
     * @Author: lmf
     * @Date: 2021/2/23
     * 获取定点售卖配置
     */
    @ApiOperation(value ="获取定点售卖配置",notes = "必须经过auth授权")
    @GetMapping("/getHotelSaleTime")
    public Result<Object> getHotelSaleTime(){
        return switchHotelUpService.getHotelSaleTime();
    }

    /***
     * @Author: lmf
     * @Date: 2021/2/23
     * 对所有的酒店设置定点售卖
     */
    @ApiOperation(value ="对所有的酒店设置定点售卖",notes = "必须经过auth授权")
    @GetMapping("/pushFixPoint")
    public Result<Object> pushFixPoint(){
        return switchHotelUpService.pushFixPoint();
    }

    /***
     * @Author: lmf
     * @Date: 2021/2/26
     * 酒店进行公式分类--针对无订单的酒店分配
     */
    @ApiOperation(value ="酒店进行公式分配",notes = "必须经过auth授权")
    @GetMapping("/allotHotelAndFormula")
    public Result<Object> allotHotelAndFormula(@RequestParam(name = "genre",defaultValue = "0")Integer genre){
        new Thread(() -> switchHotelUpService.allotHotelAndFormula(genre)).start();
        return new Result<>();
    }

    /**
     * @Author: lmf
     * @Date: 2021/5/26
     * 针对有公式的酒店进行公式降级，如果到达最低等级不进行调价
     * 每个月，月初进行调整
     */
    @ApiOperation(value ="酒店进行阶梯降级",notes = "必须经过auth授权")
    @GetMapping("/hotelFormualLadderDown")
    public Result<Object> hotelFormualLadderDown(){
        new Thread(() -> switchHotelUpService.hotelFormualLadderDown()).start();
        return new Result<>();
    }

    /***
     * @Author: lmf
     * @Date: 2021/3/8
     * 清除酒店缓存的价格公式数据
     */
    @ApiOperation(value ="清除酒店缓存的价格公式数据",notes = "必须经过auth授权")
    @GetMapping("/removeHotelPriceSetCache")
    public Result<Object> removeHotelPriceSetCache(){
        new Thread(() -> switchHotelUpService.removeHotelPriceSetCache()).start();
        return new Result<>();
    }

    /***
     * @Author: lmf
     * @Date: 2021/3/12
     * 添加全量推送酒店记录
     */
    @ApiOperation(value ="添加全量推送酒店记录",notes = "必须经过auth授权")
    @PostMapping("/addPushHotelLog")
    public Result<Object> addPushHotelLog(@RequestBody SwitchPushHotelLogEntity switchPushHotelLogEntity){
        return switchPushHotelLogService.addPushHotelLog(switchPushHotelLogEntity);
    }

    /***
     * @Author: lmf
     * @Date: 2021/3/16
     * 获取全量推送的记录列表
     */
    @ApiOperation(value ="添加全量推送酒店记录",notes = "必须经过auth授权")
    @PostMapping("/getPushHotelLog")
    public Result<Object> getPushHotelLog(@RequestBody Map<String,String> params){
        return switchPushHotelLogService.getPushHotelLog(params);
    }

    /***
     * @Author: lmf
     * @Date: 2021/3/16
     * 更新所有的推送状态
     */
    @ApiOperation(value ="添加全量推送酒店记录",notes = "必须经过auth授权")
    @GetMapping("/modifyPushHotelStatus")
    public Result<Object> modifyPushHotelStatus(){
        return switchPushHotelLogService.modifyPushHotelStatus();
    }

    /***
     * @Author: lmf
     * @Date: 2021/3/24
     * 创建表
     */
    @ApiOperation(value ="创建表",notes = "必须经过auth授权")
    @GetMapping("/createTable")
    public Result<Object> createTable(){
        return switchHotelUpService.createTable();
    }

    /****
     * @Author: lmf
     * @Date: 2021/4/7
     * 获取酒店数据参与天天特价，通过美团来控制低价
     */
    @ApiOperation(value ="获取酒店数据参与天天特价，通过美团来控制低价",notes = "必须经过auth授权")
    @GetMapping("/getJoinActiveHotelList")
    public Result<Object> getJoinActiveHotelList(){
        return switchHotelUpService.getJoinActiveHotelList();
    }


    /****
     * @Author: lmf
     * @Date: 2021/4/9
     * 初始化房型数据到缓存
     */
    @ApiOperation(value ="初始化酒店数据到缓存",notes = "必须经过auth授权")
    @GetMapping("/initSaleHotelRoomToCache")
    public Result<Object> initSaleHotelRoomToCache(){
        return switchHotelUpService.initSaleHotelRoomToCache();
    }

    /***
     * @Author: lmf
     * @Date: 2021/4/14
     * 初始化房型缓存数据
     */
    @ApiOperation(value = "初始化在售酒店房型到缓存",notes = "必须经过auth授权")
    @GetMapping("/initSaleHotelRoomWindowToCache")
    public Result<Object> initSaleHotelRoomWindowToCache(){
        ExecutorService executorService = Executors.newFixedThreadPool(1);
        executorService.submit(()->{
            switchHotelUpService.initSaleHotelRoomWindowToCache();
        });
        executorService.shutdown();
        return new Result<>();
    }

    /***
     * @Author: lmf
     * @Date: 2021/4/15
     * 调整价格公式
     */
    @ApiOperation(value = "月初佣金调整",notes = "必须经过auth授权")
    @PostMapping("/adjustHotelPirceFormula")
    public Result<Object> adjustHotelPirceFormula(@RequestBody Map<String,String> params){
        Integer genre= Integer.valueOf(params.get("genre"));
        switchPriceBaseSetService.adjustHotelPirceFormula(genre);
        return new Result<>();
    }

    /***
     * @Author: lmf
     * @Date: 2021/4/23
     * 针对异常数据进行重新推送
     */
    @ApiOperation(value = "针对异常数据进行重新推送",notes = "必须经过auth授权")
    @GetMapping("/refreshPushRoomStatusAndPrice")
    public Result<Object> adjustHotelPirceFormula(){
        return switchHotelUpService.refreshPushRoomStatusAndPrice();
    }


    /***
     * @Author: lmf
     * @Date: 2021/4/27
     * 获取要上架的酒店数据文件列表
     */
    @SneakyThrows
    @ApiOperation(value = "针对异常数据进行重新推送",notes = "必须经过auth授权")
    @RequestMapping(value = "/exportHotel",produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
    public void exportHotel(@RequestBody Map<String,Integer> params, HttpServletResponse response){
        Integer num=params.get("num");
        XSSFWorkbook wb= switchHotelUpService.exportHotel(num);
        OutputStream outputStream =null;
        try {
            String time=DateUtil.getNextDays(0);
            String fileName = "一线"+time+"上新数酒店"+num+"家.xlsx";
            fileName=URLEncoder.encode(fileName,"UTF-8");
            log.info("========fileName的名字为{}======",fileName);
            //设置ContentType请求信息格式
            response.reset();
            response.setHeader("content-Type", "application/vnd.ms-excel");
            response.setContentType("application/octet-stream;charset=UTF-8");
            response.setHeader("Content-disposition", "attachment;filename=" + fileName);
            outputStream = response.getOutputStream();
            wb.write(outputStream);
            outputStream.flush();
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            if(outputStream!=null){
                outputStream.close();
            }
        }
    }
    /***
     * @Author: lmf
     * @Date: 2021/4/29
     * 根据订单号找到房型对应的时间戳，展示方便排查
     */
    @ApiOperation(value = "根据订单号找到房型对应的时间戳",notes = "必须经过auth授权")
    @PostMapping("/getOrderRoomInfo")
    public Result<Object> getOrderRoomInfo(@RequestBody Map<String,String> params){
        String orderId=params.get("orderId");
        switchOrderInfoService.getOrderRoomInfo(orderId);
        return new Result<>();
    }


    /**
     * 获取酒店的售卖状态
     */
    @ApiOperation(value = "针对夜间停售酒店重新上架",notes = "必须经过auth授权")
    @GetMapping("/getHolelStatus")
    public Result<Object> getHolelStatus(){
        return switchHotelUpService.getHolelStatus();
    }
    /**
     * 记录直采满房美团有房的数据
     */
    @ApiOperation(value = "记录直采满房美团有房的数据",notes = "必须经过auth授权")
    @GetMapping("/recordRoomStatusLog")
    public Result<Object> recordRoomStatusLog(){
        return switchHotelUpService.recordRoomStatusLog();
    }

    /**
     * 携程房根据效应价格房态，如果产品对应没有价格房态缓存，默认认为失效
     */
    @ApiOperation(value = "记录直采满房美团有房的数据",notes = "必须经过auth授权")
    @GetMapping("/dealRoomFailure")
    public Result<Object> dealRoomFailure(){
        return switchHotelUpService.dealRoomFailure();
    }
    /**
     * 针对第三公式的酒店进行调价，根据代理通的商机数据 轮出率为0的进行降价处理
     */
    @ApiOperation(value = "针对第三公式的酒店进行调价，根据代理通的商机数据 轮出率为0的进行降价处理",notes = "必须经过auth授权")
    @PostMapping("/adjustHotelFormulaByOutputIsZero")
    public Result<Object> adjustHotelFormulaByOutputIsZero(@RequestParam("excelFile") MultipartFile excelFile){
        if(excelFile.isEmpty()){
            return new Result<>("上传失败");
        }
        ExecutorService executorService = Executors.newFixedThreadPool(1);
        switchHotelUpService.adjustHotelFormulaByOutputIsZero(excelFile);
        executorService.shutdown();
        return new Result<>();
    }
    /**
     * 匹配携程-美团上架的酒店房型相关信息：价格、房态、早餐信息
     */
    @PostMapping("/compareHotelRoomInfoByApi")
    @ApiOperation(value = "根据vo获取对应携程-美团酒店下的房型",notes = "必须经过oauth2授权")
    public Result<Object> compareHotelRoomInfoByApi(@RequestBody CompareHotelRoomVo compareHotelRoomVo){
        return switchHotelUpService.compareHotelRoomInfoByApi(compareHotelRoomVo);
    }
    /**
     * 开启促销活动
     */
    @ApiOperation(value = "开启促销活动",notes = "必须经过auth授权")
    @PostMapping("/openActive")
    public Result<Object> openActive(@RequestParam("excelFile") MultipartFile excelFile, @RequestParam("genreId")Integer genreId){
        if(excelFile.isEmpty()){
            return new Result<>("上传失败");
        }
        ExecutorService executorService = Executors.newFixedThreadPool(1);
        switchHotelUpService.openActive(excelFile,genreId);
        executorService.shutdown();
        return new Result<>();
    }
    /**
     * 新增活动类型
     */
    @PostMapping("/addActive")
    @ApiOperation(value = "新增活动类型",notes = "必须经过oauth2授权")
    public Result<Object> addActive(@RequestBody SwitchHotelActiveGenreEntity switchHotelActiveGenreEntity){
        return switchHotelUpService.addActive(switchHotelActiveGenreEntity);
    }
    /**
     * 获取活动数据类型列表
     */
    @ApiOperation(value = "开启促销活动",notes = "必须经过auth授权")
    @GetMapping("/getActiveList")
    public Result<Object> getActiveList(){
        return switchHotelUpService.getActiveList();
    }

    /**
     * 针对优势酒店->普通酒店 后面天数进行关房
     */
    @ApiOperation(value = "针对优势酒店->普通酒店 后面天数进行关房",notes = "必须经过auth授权")
    @GetMapping("/switchVipToNormalCloseStatus")
    public Result<Object> switchVipToNormalCloseStatus(){
        return switchHotelUpService.switchVipToNormalCloseStatus();
    }
    /**
     * 导出有订单的酒店数据
     */
    @SneakyThrows
    @ApiOperation(value = "导出有订单的酒店数据",notes = "必须经过auth授权")
    @RequestMapping(value = "/exportOrderHotel",produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
    public void exportOrderHotel(HttpServletResponse response){
        XSSFWorkbook wb= switchHotelUpService.exportOrderHotel();
        OutputStream outputStream =null;
        try {
            String time=DateUtil.getNextDays(0);
            String fileName = "一线"+time+"订单酒店数据.xlsx";
            fileName=URLEncoder.encode(fileName,"UTF-8");
            log.info("========fileName的名字为{}======",fileName);
            //设置ContentType请求信息格式
            response.reset();
            response.setHeader("content-Type", "application/vnd.ms-excel");
            response.setContentType("application/octet-stream;charset=UTF-8");
            response.setHeader("Content-disposition", "attachment;filename=" + fileName);
            outputStream = response.getOutputStream();
            wb.write(outputStream);
            outputStream.flush();
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            if(outputStream!=null){
                outputStream.close();
            }
        }
    }
    /**
     * 获取天天特价酒店数据
     */
    @SneakyThrows
    @ApiOperation(value = "获取天天特价酒店数据",notes = "必须经过auth授权")
    @RequestMapping(value = "/exportActiveHotel",produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
    public void exportActiveHotel(@RequestBody Map<String,Integer> params, HttpServletResponse response){
        Integer num=params.get("num");
        XSSFWorkbook wb= switchHotelUpService.exportActiveHotel(num);
        OutputStream outputStream =null;
        try {
            String time=DateUtil.getNextDays(0);
            String fileName = "二线"+time+"天天特价订单酒店数据.xlsx";
            fileName=URLEncoder.encode(fileName,"UTF-8");
            log.info("========fileName的名字为{}======",fileName);
            //设置ContentType请求信息格式
            response.reset();
            response.setHeader("content-Type", "application/vnd.ms-excel");
            response.setContentType("application/octet-stream;charset=UTF-8");
            response.setHeader("Content-disposition", "attachment;filename=" + fileName);
            outputStream = response.getOutputStream();
            wb.write(outputStream);
            outputStream.flush();
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            if(outputStream!=null){
                outputStream.close();
            }
            wb.close();
        }
    }
    /**
     * 获取酒店的售卖房型取消规则信息
     */
    @SneakyThrows
    @ApiOperation(value = "获取酒店的售卖房型取消规则信息",notes = "必须经过auth授权")
    @GetMapping(value = "/getSaleHotelRoomCanceleRule")
    public Result<Object> getSaleHotelRoomCanceleRule(){
        return switchHotelUpService.getSaleHotelRoomCanceleRule();
    }

    /**
     * 导入天天特价酒店数据入表和缓存
     * @param excelFile
     * @return
     */
    @ApiOperation(value = "导入天天特价酒店数据入表和缓存",notes = "必须经过auth授权")
    @PostMapping("/openActiveHotel")
    public Result<Object> openActiveHotel(@RequestParam("excelFile") MultipartFile excelFile){
        if(excelFile.isEmpty()){
            return new Result<>("上传失败");
        }
        ExecutorService executorService = Executors.newFixedThreadPool(1);
        switchHotelUpService.openActiveHotel(excelFile);
        executorService.shutdown();
        return new Result<>();
    }
    /**
     * 夜间控制数据列表
     */
    @ApiOperation(value = "夜间控制数据列表",notes = "必须经过auth授权")
    @GetMapping("/limitNightList")
    public Result<Object> limitNightList(){
        return switchHotelUpService.limitNightList();
    }
    /**
     * 夜间控制数据设置
     */
    @ApiOperation(value = "夜间控制数据列表",notes = "必须经过auth授权")
    @PostMapping("/setLimitNight")
    public Result<Object> setLimitNight(@RequestBody Map<String,String> map){
        return switchHotelUpService.setLimitNight(map);
    }

    /**
     * 普通酒店 日期下降
     */
    @ApiOperation(value = "夜间控制数据列表",notes = "必须经过auth授权")
    @GetMapping("/adjsutCommonHotelSaleDays")
    public Result<Object> adjsutCommonHotelSaleDays(){
        ExecutorService executorService = Executors.newFixedThreadPool(1);
        switchHotelUpService.adjsutCommonHotelSaleDays();
        executorService.shutdown();
        return new Result<>();
    }

}
